
$(document).ready(function(){
	//alert("Ok");
	$.ajax({
        type : 'post',
        url  : '/tbpoject/commoditySortControler/getAllCommoditySortJson',
        contentType : 'application/json; charset = utf-8',
        data : '',
        dataType : 'json',
        success : function(data){
        	var txt = "";
        	for(var i = 0; i < data.length; i++){
        		if(data[i].pid == '0'){
            		$(".side-li").append('<li class="s_' + data[i].id + '"><h3 style="">' + data[i].name + '<span class="fa fa-angle-right fa-loc" style=""></span></h3></li>');
            		$(".hiden-box").append('<li data-hidden="li" id="hiden-' + data[i].id + '"><div class="sub-nav-right"></div></li>');
            		for(var j=0; j<data.length; j++){
            			if(data[j].pid == data[i].id){
            				$("#hiden-"+data[i].id+" > .sub-nav-right").append('<div class="cell-box"><h1>' + data[j].name + '</h1><div class="a-box" id = "hiden-' + data[j].id + '"></div></div>');
            				for(var k=0; k<data.length; k++){
            					if(data[k].pid == data[j].id){
                    				//alert("i = " + i + " j = " + j + " k = " + k)
                					$("#hiden-"+data[j].id).append('<a href="' + data[k].address + '">' + data[k].name + '</a><span>|</span>');
                					
            					}
            				}
            			}
            		}
        		}
        	}
        	xxxxx();
        },
        error : function(){
            alert("请检查网络或联系管理员")
        }
    });
});

function xxxxx(){
    var scTop = 0,
        beginH = 138,
        wW = $(window).width(),
        classN,
        num;
    $(window).scroll(function(){
        scTop = $(window).scrollTop();
        beginH = 138;
        switch (scTop){
            case 600: beginH -= 45;break;
            case 500: beginH -= 50;break;
            case 400: beginH -= 55;break;
            case 300: beginH -= 60;break;
            case 200: beginH -= 65;break;
            default : beginH = 138;break;
        }
    });
    $('.side-li > li').hover(function(){
        $(this).find('h3').css({border: 'none'})
            .end().find('span').css({color: "#f40"});
        classN = $(this).attr('class');
        num = classN.substring(2, classN.length);

        switch (scTop){
            case 0: if(num > 14){ beginH += 120}else if(num >= 12){beginH += 41}; break;
            case 100: if(num == 1){beginH -= 27}else if(num == 16){beginH += 7}; break;
            case 200: num < 5 ? beginH -= 60 : beginH -= 30; break;
            case 300: num < 8 ? beginH -= 60 : beginH -= 40; break;
            case 400: num <= 11 ? beginH -= 50 : beginH += 10; break;
            case 500: num < 14 ? beginH -= 50 : ''; break;
            case 600: num <= 16 ? beginH -= 50 : ''; break;
            default : beginH = 138;break;
        }

        $('.hiden-box').show()
            .css({
                left: ((wW - 1190)/2 + 149),
                top:  beginH
            }).animate({width: '500px'}, 300);
        $('.hiden-box > li').hide();
        $('#hiden-'+num).fadeIn(200);
        beginH = 138;
    }, function(){
        $(this).find('h3').css({border: ''})
            .end().find('span').css({color: ""});
        $('.hiden-box').hide().css({width: '0'});
    });
    $('.hiden-box').hover(function(){
        $('.s_'+num).css({
            border: '1px solid #f40',
            borderRight: '1px solid #fff'
        }).find('h3').css({border: 'none'})
            .end().find('span').css({color: "#f40"});
        $(this).show().css({width: '500px'});
    }, function(){
        $('.s_'+num).css({
            border: '',
            borderRight: ''
        }).find('h3').css({border: ''})
            .end().find('span').css({color: ""});
        $(this).animate({
            width: 0
        }, 200).hide(200);
    });

}